from PIL import Image
from torchvision import transforms
import cv2
from torch.utils.tensorboard import SummaryWriter

writer = SummaryWriter("logs")

img_path = "datas/train/ants/0013035.jpg"
image = Image.open(img_path)

# ToTensor usage

to_tensor = transforms.ToTensor()
tensor_img = to_tensor(image)
writer.add_image("ToTensor", tensor_img, 1)


# compose usage
compose = transforms.Compose([transforms.CenterCrop(100), transforms.ToTensor()])
compose_img = compose(image)
print(compose_img)
writer.add_image("Compose", compose_img, 1)

# Normalize
normalize = transforms.Normalize([0.5, 0.5 , 0.5], [0.5, 0.5 , 0.5])
normalize_img = normalize(tensor_img)
print(tensor_img[0][0][0])
print(normalize_img[0][0][0])
writer.add_image("Normalize", normalize_img, 1)

# Resize
resize = transforms.Resize((512, 512))
resized_img = resize(image)
print(image.size)
print(resized_img.size)
writer.add_image("Resize", to_tensor(resized_img), 1)

writer.close()

